<template>
	<view class="content">
		<scroll-view style="height: 100vh;" class="wid100" scroll-y="true" @scrolltolower="lower">
			<wsj v-if="list.length == 0" zs='0'></wsj>
			<view style="height: 1rpx;"></view>
			<block v-for="(item,index) in list" :key="index">
				<view class="wid90 mar mar-top30 borRad10 bacFFF" @click="tiaozhuan('/pages/technician/particulars?id='+item.tech.id)"
					style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);">
					<view style="height: 25rpx;"></view>
					<view class="wid90 mar">
						<view class="dis disAl">
							<view class="wid25">
								<image :src="item.tech.coverimg" style="width: 100rpx;height: 100rpx;" class="borRad50"></image>
							</view>
							<view style="height: 100rpx;border-bottom: 1rpx solid #E1DFDF;width: 75%;">
								<view class="dis disAl disJuB">
									<view class="dis disAl">
										<view class="foSi30 fowe600">{{item.tech.name}}</view>
										<view class="dis disAl disJuC foSi15 coFFF mar-left20" :style="'background-color: '+theme.seco_color+';'"
											style="width: 80rpx;height: 28rpx;border-radius: 5rpx;">更多照片</view>
									</view>
									<view style="width: 146rpx;height: 28rpx;border-radius: 5rpx;" class="dis disAl disJuC foSi15 fowe600"
									 :style="'background-color: '+theme.main_color+'21;color: '+theme.main_color+';'">最早可约：{{item.tech.start_time}}</view>
								</view>
								<view class="mar-top20 dis disAl disJuB">
									<view class="dis disAl">
										<image src="../../static/pingjia.png" style="width: 25rpx;height: 25rpx;margin-right: 5rpx;"></image>
										<view class="foSi25 fowe600" style="color: #FEC44A;">{{item.tech.star}}</view>
										<view style="width: 2rpx;background-color: #BFBFBF;height: 22rpx;margin: 0 15rpx;"></view>
										<view class="foSi20 fowe600">已服务<span :style="'color: '+theme.main_color+';'">{{item.tech.service_order_num}}</span>单</view>
									</view>
									<view class="dis disAl">
										<uni-icons type="location-filled" size="30rpx" :color="theme.main_color"></uni-icons>
										<view class="foSi25 mar-left10">{{item.distance}}</view>
									</view>
								</view>
							</view>
						</view>
						<view class="dis disAl" style="height: 76rpx;">
							<view class="wid25">
								<view style="width: 100rpx;">
									<view class="mar dis disAl disJuC borRad40 coFFF foSi15" :style="'background-color: '+theme.main_color+';'"
										style="width: 80rpx;height: 29rpx;">{{item.status == 1?'可服务':item.status == 2?'服务中':'可预约'}}</view>
								</view>
							</view>
							<view class="dis disAl disJuB" style="width: 75%;">
								<view class="dis disAl">
									<view class="dis disAl">
										<image src="../../static/pinglu1.png" style="width: 24rpx;height: 24rpx;"></image>
										<view class="mar-left10 fowe600 foSi25">{{item.tech.comment_num}}</view>
									</view>
									<view class="dis disAl mar-left30" @click.stop="shouchang(index)">
										<!-- <image src="../../static/xihuan.png" style="width: 34rpx;height: 31rpx;"></image> -->
										<uni-icons type="star-filled" size="30rpx" :color="theme.main_color"></uni-icons>
										<view class="mar-left10 foSi25">{{item.tech.coll_num}}</view>
									</view>
									<view class="dis disAl mar-left30">
										<image src="../../static/xiangqing.png" style="width: 22rpx;height: 24rpx;"></image>
										<view class="mar-left10 fowe600 foSi20">详情</view>
									</view>
								</view>
								<view class="dis disAl disJuC coFFF foSi20" :style="'background-color: '+theme.main_color+';'"
									style="width: 120rpx;height: 42rpx;border-radius: 5rpx;">立即预约</view>
							</view>
						</view>
					</view>
				</view>
			</block>
			<view style="height: 50rpx;"></view>
		</scroll-view>
	</view>
</template>

<script>
	import wsj from '../common/w_sj.vue'
	export default {
		components: {
			wsj
		},
		data() {
			return {
				url: this.global.url,
				last_page: 0,
				page: 1,
				list: [],
				theme: null
			}
		},
		onLoad() {
			this.theme = uni.getStorageSync('theme')
			this.getList()
		},
		methods: {
			shouchang(index){
				var that = this;
				if(!uni.getStorageSync('token')){
					return uni.showToast({title: '请登录',icon: 'error',duration: 2000}) 
				}
				uni.request({
					url: that.global.url + 'api/qianyu_smfw/trends/collect_add',
					method: "POST",
					header: {
						'site-id': that.global.site_id,//自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						tech_id: that.list[index].tech_id,
						type: 2
					},
					success(res) {
						let result = res.data
						if (result.code == 1) {
							that.list.splice(index, 1);
						}else{
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							}) 
						}
					}
				})
			},
			getList(){
				var that = this;
				uni.request({
					url: that.global.url + 'api/qianyu_smfw/user/coll_list',
					method: "POST",
					header: {
						'site-id': that.global.site_id ,//自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						lon: uni.getStorageSync('lon')?uni.getStorageSync('lon'):125.35043,
						lat: uni.getStorageSync('lat')?uni.getStorageSync('lat'):43.86414,
						page: 1
					},
					success(res) {
						let result = res.data
						if (result.code == 1) {
							that.last_page = result.data.last_page
							if(that.page == 1){
								that.list = result.data.data
							}else{
								that.list = that.list.concat(result.data.data)
							}
						}else{
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							}) 
						}
					}
				})
				
			},
			lower(e) {
				if(this.last_page > this.page){
					this.page++
					this.getList()
				}
			},
			tiaozhuan(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.content {
		min-height: 100vh;
		background-color: #F2F2F2;
	}
	.tim1{
		padding: 15rpx;
		background-color: #00C82D;
		border-radius: 5rpx;
	}
	.butt2{
		width: 125rpx;
		height: 50rpx;
		background-color: #00C82D;
		border-radius: 5rpx;
	}
</style>
